package com.example.cd5160866.materialdesgin;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;

import com.example.cd5160866.materialdesgin.capture.CaptureDialog;

import utils.utils.CaputrueUtils;

/**
 * Created by cd5160866 on 2018/1/15.
 */

public class CaptureViewActivity extends AppCompatActivity {
    ImageView result;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_capture);
        result = (ImageView) findViewById(R.id.view_result);
        findViewById(R.id.bt_capture_group).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                result.setImageBitmap(CaputrueUtils.getCaptureView(findViewById(R.id.ll_group)));
            }
        });
        findViewById(R.id.capture_text_img).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                new CaptureDialog.Builder(CaptureViewActivity.this)
                        .create().addCaptureView(findViewById(R.id.capture_text_img)).showCapture();

                return false;
            }
        });
    }

    void capture(View view) {
        switch (view.getId()) {
            case R.id.capture_text:
                break;
            case R.id.capture_text_img:
                break;
            case R.id.capture_button:
                break;
            case R.id.capture_img:
                break;
        }
        result.setImageBitmap(CaputrueUtils.getCaptureView(view));
    }

    public static int dip2pixel(Context context, float n) {
        int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, n, context.getResources().getDisplayMetrics());
        return value;
    }
}
